#!/bin/sh

# 使用说明，用来提示输入参数
usage() {
	echo "Usage: sh 执行脚本.sh [ port | start | modules | stop | rm ]"
	echo "Usage: sh 执行脚本.sh start [ all | prometheus | grafana | cadvisor | blackbox | pushgateway]"
	exit 1
}

# # 开启所需端口
# port(){
# 	firewall-cmd --add-port=80/tcp --permanent
# 	firewall-cmd --add-port=8080/tcp --permanent
# 	firewall-cmd --add-port=8848/tcp --permanent
# 	firewall-cmd --add-port=9848/tcp --permanent
# 	firewall-cmd --add-port=9849/tcp --permanent
# 	firewall-cmd --add-port=6379/tcp --permanent
# 	firewall-cmd --add-port=3306/tcp --permanent
# 	firewall-cmd --add-port=9100/tcp --permanent
# 	firewall-cmd --add-port=9200/tcp --permanent
# 	firewall-cmd --add-port=9201/tcp --permanent
# 	firewall-cmd --add-port=9202/tcp --permanent
# 	firewall-cmd --add-port=9203/tcp --permanent
# 	firewall-cmd --add-port=9300/tcp --permanent
# 	service firewalld restart
# }

start(){
	if [ -z "$2" ]; then
		echo "错误：启动服务需要指定服务名称"
		usage
	fi

	service="$2"
	echo "启动 $service"

	case "$service" in
		"prometheus")
			docker-compose up -d prometheus
			;;
		"grafana")
			docker-compose up -d grafana
			;;
		"blackbox")
			docker-compose up -d blackbox
			;;
		"cadvisor")
			docker-compose up -d cadvisor
			;;
		"pushgateway")
			docker-compose up -d pushgateway
			;;
		"all")
			docker-compose up -d
			;;
		# "playlistdl")
		# 	docker-compose up -d playlistdl
		# 	;;
		*)
			echo "未知服务: $service"
			exit 1
			;;
	esac
}

# 关闭所有环境/模块
stop(){
	docker-compose stop
}

# 删除所有环境/模块
rm(){
	docker-compose rm
}

# 根据输入参数，选择执行对应方法，不输入则执行使用说明
case "$1" in
"port")
	port
	;;
"start")
	start "$@"
	;;
"stop")
	stop
	;;
"rm")
	rm
	;;
*)
	usage
	;;
esac